package xyx.springboot.serviceimpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyx.springboot.mapper.JpaMapper;
import xyx.springboot.model.User;
import xyx.springboot.service.JpaService;

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Service
public class JpaServiceImpl implements JpaService {
    @Autowired
    JpaMapper jpaMapper;

    //查询全部
    @Override
    public List<User> listAll() {
        return jpaMapper.findAll();
    }

    //新增
    @Override
    public void save(User user) {
        jpaMapper.save(user);
    }

    //修改
    @Override
    public void update(User user) {
        jpaMapper.saveAndFlush(user);
    }

    //删除
//    @Override
//    public void delete(int id) {
//        jarMapper.delete(jarMapper.findUserById(id));
//    }

    //查询用户是否存在
    @Override
    public Optional<User> findById(int id) {
        return jpaMapper.findById(id);
    }

    //查询用户信息
    @Override
    public User getById(int id) {
        return jpaMapper.getById(id);
    }

    //自定义查询
    @Override
    public Map myfind(int id) {
        return jpaMapper.myfind(id);
    }

}
